// pages/exercises/exercisesDetail/exercisesDetail.js
var app = getApp();
var config = require('../../../../config.js');
const http = require('../../../../http.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bankId:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  
  onLoad: function (options) {
    console.log(options)
    this.setData({
      bankId: options.bankId
    })
     this.getDetails();
  },
  getDetails:function(){
    var that = this;
    http.request(
      config.getExercisesType,
      'POST',{
        catId:this.data.bankId,
        page:1,
        pageSize:12     
      },
      function (res) {
        var exerciseInfo = res.rows[0];
          if (exerciseInfo){
            that.setData({
              des: exerciseInfo.introduce,
              name: exerciseInfo.title,
              img: exerciseInfo.imgUrl,
              source: exerciseInfo.source,
              count: exerciseInfo.questionCount
            })
      
      }
        
      },
      function (err) {
        wx.showToast({
          title: err,
          icon: 'none',
        })
      }, true
    )

  },
  //获取列表数据
  // getDetails: function () {
  //   var that = this;
  //   wx.request({
  //     url: config.getExercisesDetails,
  //     method: "POST",
  //     data: {
  //       openId: app.globalData.openid,
  //       bankId: that.data.bankId
  //     },
  //     success: function (ret) {
  //       var data = ret.data
  //       if (data.success == 0) {
  //         var exerciseInfo = data.rows;
  //         if (exerciseInfo){

  //           that.setData({
  //             des: exerciseInfo.instroduce,
  //             name: exerciseInfo.bankName,
  //             img: exerciseInfo.imgUrl,
  //             source: exerciseInfo.source,
  //             count: exerciseInfo.questionCount
  //           })

  //         }
          
      
  //       }
  //     }
  //   })
  // },


  /**
   * 跳转练习页
   */
  toExercising: function () {
    // if (!app.globalData.userInfo) {
    //   console.log("判断是否授权，否则打开授权");
    //   //未授权
    //   wx.navigateTo({
    //     url: '../authorization/authorization?pageId=' + config.toRanks
    //   })
    //   return;
    // }
    wx.navigateTo({
      url: '../exercisesLoading/exercisesLoading?bankId=' + this.data.bankId
    })
   

  },

  //邀请好友答题
  onShareAppMessage(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '依法治藏',
      path: '/pages/index/index',
      success: function (res) {
        console.log(res)
      }
    }
  },

 
})